package com.electric.qrapp.utils.function

import android.os.Environment
import java.io.File

/**
 *@author created by WA03675
 *@date  2022-03-22 09:28
 *@des
 */
fun deleteFile(fileName: String): Boolean {
    val file = File(fileName);
    return if (!file.exists()) {
        false;
    } else {
        if (file.isFile) {
            file.delete()
        } else {
            deleteDirectory(fileName);
        }
    }
}

fun deleteDirectory(fileName: String): Boolean {
    val file = File(fileName);
    return if (file.isFile && file.exists()) {
        file.delete();
        true;
    } else {
        false;
    }
}

//获取文件类型
fun getFileType(filePath: String): String? {
    val lastPoint = filePath.lastIndexOf(".")
    if (lastPoint == -1) return null
    return filePath.substring(lastPoint + 1, filePath.length)
}

fun getSaveFileDir(): String = Environment.getExternalStorageDirectory()
    .absolutePath.toString() + File.separator + "cloud" + File.separator + "img"